XMas.MainMenu = function (game) { };
XMas.MainMenu.prototype = {
    create: function() {
        // display images
        var self = this;
        this.add.sprite(0, 0, 'background');
        var starTweenDefault = 400;
        XMas.Config.setting.logoText.forEach(function(item) {
            var rdArray = self.rnd.integerInRange(1, XMas.Config.setting.logoText.length - 4);
            var itemX = parseInt(item.x);
            var itemY = parseInt(item.y);
            var lt = self.add.sprite(item.x, item.y, 'logo_' + item.keyID);
            if (item.keyID > 8) {
                //add star light into sprite
                var light1 = self.add.sprite(itemX + 10 * self.rnd.integerInRange(1, 8), itemY + 20, 'light1');
                var light2 = self.add.sprite(itemX + 10 * self.rnd.integerInRange(1, 8), itemY + 80, 'light2');
                var light3 = self.add.sprite(itemX + 10 * self.rnd.integerInRange(1, 8), itemY + 90, 'light3');
                light1.alpha = 0;
                light3.alpha = 0;
                light2.alpha = 0;
                //add tween to star light to loop animations
                self.add.tween(light1).to({ alpha: 1 }, 1500, Phaser.Easing.Linear.None, true, starTweenDefault * self.rnd.integerInRange(8, 12), -1, true);
                self.add.tween(light2).to({ alpha: 1 }, 1500, Phaser.Easing.Linear.None, true, starTweenDefault * self.rnd.integerInRange(8, 12), -1, true);
                self.add.tween(light3).to({ alpha: 1 }, 1500, Phaser.Easing.Linear.None, true, starTweenDefault * self.rnd.integerInRange(8, 12), -1, true);
                starTweenDefault += 100;
                
                lt.alpha = 0;
                lt.scale.setTo(10, 10);
                self.time.events.add(300 * rdArray, XMas.Effect.timeWaitAnotherEffect, self, self, lt);
            } else {
                lt.y = -90;
                self.add.tween(lt).to({ y: itemY }, 2400, Phaser.Easing.Bounce.Out, true, 1000 + 400 * rdArray, true);
            }
        });
        
        // add the button that will start the game
        //  This sprite is using a texture atlas for all of its animation data
        var startButton = this.add.sprite(XMas.GlobalVariables.GAME_WIDTH / 2 - 95, XMas.GlobalVariables.GAME_HEIGHT - 155, 'button-start');
        //  Here we add a new animation called 'run'
        //  We haven't specified any frames because it's using every frame in the texture atlas
        startButton.animations.add('run');
        //  And this starts the animation playing by using its key ("run")
        //  5 is the frame rate (5fps)
        //  true means it will loop when it finishes
        startButton.animations.play('run', 5, true);
        startButton.inputEnabled = true;
        startButton.input.useHandCursor = true;
        startButton.events.onInputDown.add(this.startGame, this);
        //Snow
        XMas.Snow.prototype.initialize(this);
        // add music to game world and play
        
        XMas.backgroundMusic.play('', 5, 1, true);
        // add transition when change page
        var blackFade = this.add.sprite(0, 0, "blackfade");
        XMas.Effect.transitionPage(blackFade, 3000, 0, this);
    },
    startGame: function() {
        // start the Game state
        
        this.state.start('Game');
        //this.state.destroy();
    }
};